generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 129
Autoharness: Derive Arbitrary for structs and enums
#4167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tautschnig
merged 6 commits into
model-checking:main
from
carolynzech:autoharness-derive-arbitrary
Jun 27, 2025
Merged
Autoharness: Derive Arbitrary for structs and enums
#4167
tautschnig
merged 6 commits into
model-checking:main
from
carolynzech:autoharness-derive-arbitrary
Jun 27, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the compiler can derive arbitrary now, so update the test accordingly
8d32535 to
8cb3b04
Compare
Contributor
Author
|
I recommend reviewing commit-by-commit. In the first commit, review in execution order: i.e., first look at the changes in |
tautschnig
approved these changes
Jun 27, 2025
Merged
via the queue into
model-checking:main
with commit Jun 27, 2025
0024103
27 of 28 checks passed
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jul 3, 2025
Fixes and improvements to the derivation of Arbitrary in the compiler introduced in #4167, along with a fix for #4189 and some other small improvements to autoharness that I noticed along the way. Best reviewed commit by commit. Resolves #4189 Towards #3832 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jul 3, 2025
Auto generated release notes: ## What's Changed * Edit quantifiers' documentation. by @thanhnguyen-aws in #4142 * Fix the bug of using multiple hidden variables for the prev of the same Expr by @thanhnguyen-aws in #4150 * Remove `assess` subcommand by @carolynzech in #4111 * Optimize goto binary exporting in `cprover_bindings` by @AlexanderPortland in #4148 * Add the option to generate performance flamegraphs by @AlexanderPortland in #4138 * Fix the bug: Static union values can panic Kani by @thanhnguyen-aws in #4112 * Update toolchain to 2025-06-13 by @carolynzech in #4152 * Automatic cargo update to 2025-06-16 by @github-actions in #4156 * Major-version update cargo dependencies by @tautschnig in #4158 * Upgrade Rust toolchain to 2025-06-16 by @tautschnig in #4157 * Bump tests/perf/s2n-quic from `3129ad5` to `c6e694e` by @dependabot in #4160 * Bump tests/perf/s2n-quic from `c6e694e` to `b1b5bf8` by @dependabot in #4164 * Upgrade Rust toolchain to 2025-06-17 by @tautschnig in #4163 * Automatic cargo update to 2025-06-23 by @github-actions in #4172 * Stub panics during MIR transformation by @AlexanderPortland in #4169 * Bump tests/perf/s2n-quic from `b1b5bf8` to `32ba87d` by @dependabot in #4175 * Handle enums with zero or one variants by @zhassan-aws in #4171 * Introduce compiler timing script & CI job by @AlexanderPortland in #4154 * Upgrade Rust toolchain to 2025-06-18 by @tautschnig in #4166 * Cache dependencies for CI jobs by @AlexanderPortland in #4181 * Autoharness: Derive `Arbitrary` for structs and enums by @carolynzech in #4167 * Upgrade Rust toolchain to 2025-06-27 by @tautschnig in #4182 * Include wget in dependencies by @zhassan-aws in #4183 * Automatic cargo update to 2025-06-30 by @github-actions in #4186 * Add support for loop assigns in loop contracts by @thanhnguyen-aws in #4174 * Upgrade toolchain to 06/30 by @carolynzech in #4188 * Optimize reachability with non-mutating global passes by @AlexanderPortland in #4177 * Bump tests/perf/s2n-quic from `32ba87d` to `b8f8cca` by @dependabot in #4190 * Bump ncipollo/release-action from 1.16.0 to 1.18.0 by @dependabot in #4191 * Upgrade toolchain to 07/02 by @carolynzech in #4195 * Automatic Derivation Fixes by @carolynzech in #4194 **Full Changelog**: kani-0.63.0...kani-0.64.0 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While generating automatic harnesses, derive
Arbitraryimplementations for structs and enums that don't have implementations.Implementation Overview
automatic_harness_partition, we mark a function as eligible for autoharness if its arguments either:a. implement
Arbitrary, orb. are structs/enums whose fields implement
Arbitrary.AutomaticHarnessPassruns as before, but now may generate harnesses that callkani::any()for structs/enums that do not actually implementArbitrary. See the definition ofkani::any():kani/library/kani_core/src/lib.rs
Lines 274 to 276 in b64e59d
The initial
kani::any()call resolves fine, but the compiler would ICE if it tried to resolveT::any().AutomaticArbitraryPassthat runs after theAutomaticHarnessPass. This pass detects the calls to nonexistentT::any()s and replaces them with inlinedT::any()implementations. These implementations are based on what Kani's derive macros for structs and enums produce.Example
Given the automatic harness
foo_harnessproduced byAutomaticHarnessPass:AutomaticArbitraryPasswill rewritekani::any():as:
i.e., replace the call to
Foo::any()with what the derive macro would have produced for the body ofFoo::any()(had the programmer used the derive macro instead).Limitations
The fields need to have
Arbitraryimplementations; there is no support for recursive derivation. See the tests for examples; this should be resolvable through further engineering effort.Towards #3832
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.